package com.limeng.server;

import java.io.IOException;
import java.io.InputStream;

public class Request {

    private String url;

    private String method;

    private String hostName;

    public Request(InputStream inputStream) throws IOException {

        int count = 0;
        while(count==0){
            count = inputStream.available();
        }
        byte[] b = new byte[count];

        inputStream.read(b);
        String requestInfo = new String(b);
        if(requestInfo!=null && !requestInfo.equals("")){
            String firstLineStr = requestInfo.split("\\n")[0];
            String secondLineStr = requestInfo.split("\\n")[1];
            String[] params = firstLineStr.split(" ");
            String[] hostParams = secondLineStr.split(":");
            method = params[0];
            url = params[1];
            hostName = hostParams[1].trim();
//            System.out.println("method:"+method+"********");
//            System.out.println("url:"+url+"********");
        }
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }
}
